{include file='public/header' /}

{load href="__ROOT__/static/admin/lib/bootstrap/css/bootstrap.css"}

{load href="__ROOT__/static/admin/lib/bootstrap/js/bootstrap.js"}





<body>

<div class="x-nav">

  <span class="layui-breadcrumb">

      <a href="">首页</a>

      <a href="">车型管理</a>

      <a><cite>车型列表</cite></a>

  </span>

  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">

      <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>

  </a>

</div>





<div class="x-body">



    <table class="layui-hide" id="test" lay-filter="test"></table>

    <input id="currid" type="hidden" name="curr" value="1">

   

</div>





<script type="text/html" id="toolbarDemo">

      <div class="layui-form-item"> 
        
        <form class="layui-form" action="" lay-filter="search">
          {if $qxarr['add']}
          <a class="layui-btn" lay-event="addfl"><i class="layui-icon"></i>录入新车型</a>
          {/if}
         <input type="text"  placeholder="请输入品牌、车型名称" autocomplete="off" class="layui-btn layui-btn-primary" name="name">

          <div class="layui-inline">
            <button class="layui-btn"  lay-event="searchBarFunc"><i class="layui-icon">&#xe615;</i></button>
          </div>

        </form>
      </div>
</script>



<script type="text/html" id="name">

    {{#  if(d.level == 1){ }}

      |{{d.name}}

    {{#  } }}


    {{#  if(d.level == 2){ }}

     |——{{d.name}}

    {{#  } }}


</script>


<script type="text/html" id="upname">

    {{#  if(d.pid > 0){ }}

      {{d.upinfo.name}}

    {{#  } }}


    {{#  if(d.pid == 0){ }}

      <span class="layui-btn layui-btn-xs">汽车品牌</span>

    {{#  } }}

</script>



<script type="text/html" id="barDemo">

  <div class="layui-btn-group">

      {if $qxarr['edit']}
      <button type="button" class="layui-btn" lay-event="edit">编辑</button>
      {/if}

      {if $qxarr['del']}
      <button type="button" class="layui-btn layui-btn-danger" lay-event="del">删除</button>
      {/if}

  </div>

</script>


<script type="text/html" id="switchTp">

      <input type="checkbox" name="禁用" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sxjFunc" {{ d.state == 1 ? 'checked' : '' }}>

</script>



<style type="text/css">

  /*{# 设置table每一行的height #}*/

  .layui-table-cell {

   height: 50px;

   line-height: 50px;

  }

 </style>





<script>

layui.use('table', function(){

  var table = layui.table

  ,form = layui.form;

  //第一个实例

  table.render({

    elem: '#test'

    ,height:'full-100'

    ,title:'车型列表'

    ,url: "{:url('gList')}" //数据接口
    ,page: true //开启分页

    ,limit:30

    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板

    ,cols: [[ //表头

      // {type:'checkbox', fixed: 'left'}

      {field: 'id', title: 'ID', fixed: 'left',hide:true}

      ,{field: 'name', title: '品牌、车型名称',width:300,templet: '#name'}

      ,{field: 'upname', title: '所属品牌', templet: '#upname'}

      ,{field: 'px', title: '排序', sort: true, edit:'text'}

      ,{field: 'state',  title: '启用/禁用', templet: '#switchTp',sort: true, unresize: true}

      ,{field: 'base', title: '车型价格基数', sort: true, edit:'text'}

      ,{field: 'gjbw', title: '基础检测', sort: true, edit:'text'}

      ,{field: 'wtc', title: '问题车鉴定', sort: true, edit:'text'}

      ,{field: 'jzpg', title: '价值评估', sort: true, edit:'text'}

      ,{field: 'create_time', title: '创建时间',hide:true}

      ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}

    ]]
     ,done: function(res, curr, count){
      
      $('#currid').val(curr);
      //得到当前页码
      console.log(curr); 
    
  }

  });



  

  //监听上下架操作

  form.on('switch(sxjFunc)', function(obj){

    var is_xj = obj.elem.checked?1:0;

    var is_xj_str = obj.elem.checked?'已启用':'已禁用';

    var curr = $('#currid').val();

    var index = layer.load();

    $.post("{:url('editSxj')}",{id:this.value,is_xj:is_xj},function (res) {
            layer.close(index);
            if (res == 1) {

                var data = form.val('search');
              
                table.reload('test',{
                    url: "{:url('gList')}",

                    page: {
                      curr: curr 
                    }

                   ,where: data
                   ,done: function(res, curr, count){
                      form.val('search', data);
                      $('#currid').val(curr);
                   }
                })

                layer.msg(is_xj_str+'成功',{icon:1,time:2000});
                // layer.tips(is_xj_str, obj.othis);
            }else{

                if (is_xj == 1) {
                    obj.elem.checked = false;
                }else{
                    obj.elem.checked = true;
                }
                layer.tips('暂无权限', obj.othis);
                form.render('checkbox')
            }
                

    })

  });






  //监听行工具事件

  table.on('tool(test)', function(obj){

    var data = obj.data;

    //console.log(obj)

    if(obj.event === 'del'){

      layer.confirm('确定删除？', function(index){

         $.post("{:url('del')}",{id:data.id},function (res) {

                if(res == 1){

                     obj.del();

                     layer.msg('删除成功', {icon: 1});

                }else if(res == 2)  {

                    layer.msg('删除失败,该汽车品牌下存在车型!',{icon:2,time:2000});

                }else{

                    layer.msg('没有权限',{icon:2,time:2000});
                }

            })

      });



    } else if(obj.event === 'edit'){
      x_admin_show('修改车型',"{:url('edit')}?id="+data.id);

    }

  });



 //头工具栏事件

  table.on('toolbar(test)', function(obj){

        if(obj.event === 'addfl'){

          x_admin_show('录入车型','{:url(\'add\')}');
        }else if(obj.event === 'searchBarFunc'){

              var data = form.val('search');
            
              table.reload('test',{
                  url: "{:url('gList')}",

                  page: {
                    curr: 1 //重新从第 1 页开始
                  }

                 ,where: data
                 ,done: function(res, curr, count){
                    form.val('search', data);
                    $('#currid').val(curr);
                    //得到当前页码
                    console.log(curr); 

                 }
              })


        }

  });





  //监听单元格编辑
  table.on('edit(test)', function(obj){

    var value = obj.value //得到修改后的值

    ,data = obj.data //得到所在行所有键值

    ,field = obj.field; //得到字段

    if(field=='base'){

        var old=$(this).prev().text();

        var curr = $('#currid').val();

        if(!/^[+-]?(0|([1-9]\d*))(\.\d+)?$/.test(value)){

            layer.msg('请输入数字或者小数！！!',{icon:2,time:2000});
            
            $(this).val(old);

            return;

        }

        var index = layer.load();

        $.post("{:url('editBase')}",{id:data.id,base:value,ziduan:'base'},function (res) {
                layer.close(index);
                if(res == 1){

                    var data = form.val('search');
                  
                    table.reload('test',{
                        url: "{:url('gList')}",

                        page: {
                          curr: curr 
                        }

                       ,where: data
                       ,done: function(res, curr, count){
                          form.val('search', data);
                          $('#currid').val(curr);
                       }
                    })

                    layer.msg('更改成功', {icon: 1});

                }else {

                      
                      var data = form.val('search');
                  
                      table.reload('test',{
                          url: "{:url('gList')}",

                          page: {
                            curr: curr 
                          }

                         ,where: data
                         ,done: function(res, curr, count){
                            form.val('search', data);
                            $('#currid').val(curr);

                         }
                      })

                      layer.msg('暂无权限',{icon:2,time:2000});

                      return;

                }

            })

    }else if (field=='px') {

        var old=$(this).prev().text();

        var curr = $('#currid').val();

        if(!/^\d+$/.test(value)){

            layer.msg('请输入正整数！！!',{icon:2,time:2000});
            
            $(this).val(old);

            return;

        }

        $.post("{:url('editpx')}",{id:data.id,px:value},function (res) {
        
                if(res == 1){

                    var data = form.val('search');
                  
                    table.reload('test',{
                        url: "{:url('gList')}",

                        page: {
                          curr: curr 
                        }

                       ,where: data
                       ,done: function(res, curr, count){
                          form.val('search', data);
                          $('#currid').val(curr);

                       }
                    })

                    layer.msg('更改成功', {icon: 1});

                }else {

                      
                      var data = form.val('search');
                  
                      table.reload('test',{
                          url: "{:url('gList')}",

                          page: {
                            curr: curr 
                          }

                         ,where: data
                         ,done: function(res, curr, count){
                            form.val('search', data);
                            $('#currid').val(curr);
                         }
                      })

                      layer.msg('暂无权限',{icon:2,time:2000});

                      return;

                }

            })

    }else if(field=='gjbw'){

        var old=$(this).prev().text();

        var curr = $('#currid').val();

        if(!/^[+-]?(0|([1-9]\d*))(\.\d+)?$/.test(value)){

            layer.msg('请输入数字或者小数！！!',{icon:2,time:2000});
            
            $(this).val(old);

            return;

        }

        var index = layer.load();

        $.post("{:url('editBase')}",{id:data.id,base:value,ziduan:'gjbw'},function (res) {
                layer.close(index);
                if(res == 1){

                    var data = form.val('search');
                  
                    table.reload('test',{
                        url: "{:url('gList')}",

                        page: {
                          curr: curr 
                        }

                       ,where: data
                       ,done: function(res, curr, count){
                          form.val('search', data);
                          $('#currid').val(curr);
                       }
                    })

                    layer.msg('更改成功', {icon: 1});

                }else {

                      
                      var data = form.val('search');
                  
                      table.reload('test',{
                          url: "{:url('gList')}",

                          page: {
                            curr: curr 
                          }

                         ,where: data
                         ,done: function(res, curr, count){
                            form.val('search', data);
                            $('#currid').val(curr);

                         }
                      })

                      layer.msg('暂无权限',{icon:2,time:2000});

                      return;

                }

            })

    }else if(field=='wtc'){

        var old=$(this).prev().text();

        var curr = $('#currid').val();

        if(!/^[+-]?(0|([1-9]\d*))(\.\d+)?$/.test(value)){

            layer.msg('请输入数字或者小数！！!',{icon:2,time:2000});
            
            $(this).val(old);

            return;

        }

        var index = layer.load();

        $.post("{:url('editBase')}",{id:data.id,base:value,ziduan:'wtc'},function (res) {
                layer.close(index);
                if(res == 1){

                    var data = form.val('search');
                  
                    table.reload('test',{
                        url: "{:url('gList')}",

                        page: {
                          curr: curr 
                        }

                       ,where: data
                       ,done: function(res, curr, count){
                          form.val('search', data);
                          $('#currid').val(curr);
                       }
                    })

                    layer.msg('更改成功', {icon: 1});

                }else {

                      
                      var data = form.val('search');
                  
                      table.reload('test',{
                          url: "{:url('gList')}",

                          page: {
                            curr: curr 
                          }

                         ,where: data
                         ,done: function(res, curr, count){
                            form.val('search', data);
                            $('#currid').val(curr);

                         }
                      })

                      layer.msg('暂无权限',{icon:2,time:2000});

                      return;

                }

            })

    }else if(field=='jzpg'){

        var old=$(this).prev().text();

        var curr = $('#currid').val();

        if(!/^[+-]?(0|([1-9]\d*))(\.\d+)?$/.test(value)){

            layer.msg('请输入数字或者小数！！!',{icon:2,time:2000});
            
            $(this).val(old);

            return;

        }

        var index = layer.load();

        $.post("{:url('editBase')}",{id:data.id,base:value,ziduan:'jzpg'},function (res) {
                layer.close(index);
                if(res == 1){

                    var data = form.val('search');
                  
                    table.reload('test',{
                        url: "{:url('gList')}",

                        page: {
                          curr: curr 
                        }

                       ,where: data
                       ,done: function(res, curr, count){
                          form.val('search', data);
                          $('#currid').val(curr);
                       }
                    })

                    layer.msg('更改成功', {icon: 1});

                }else {

                      
                      var data = form.val('search');
                  
                      table.reload('test',{
                          url: "{:url('gList')}",

                          page: {
                            curr: curr 
                          }

                         ,where: data
                         ,done: function(res, curr, count){
                            form.val('search', data);
                            $('#currid').val(curr);

                         }
                      })

                      layer.msg('暂无权限',{icon:2,time:2000});

                      return;

                }

            })

    }


  });



  

});

</script>











</body>

</html>